import java.util.Stack;

//最小栈；
//获取栈中最小元素，要求时间复杂度O(1);
public class MyMinStack {
    private Stack<Integer> stack;
    private Stack<Integer> MinStack;
    public MyMinStack(){
        stack=new Stack<>();
        MinStack=new Stack<>();
    }
    //向最小栈中添加元素；
    public void push(int val){
        stack.push(val);
        if(MinStack.empty()){
            MinStack.push(val);
        }else{
            int peek=MinStack.peek();
            if(val<=peek){
                MinStack.push(val);
            }
        }
    }
    //删除最小栈中的元素；
    public void pop(){
        if(stack.empty()){
            return;
        }
        int ret=stack.pop();
        if(ret==MinStack.peek()){
            MinStack.pop();
        }
    }
    //获取栈中元素；
    public int top(){
        if(stack.empty()){
            return -1;
        }
        return stack.peek();
    }
    //获取栈中最小的元素；
    public int getMin(){
        return MinStack.peek();
    }
}
